package wwj.entity;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;

public class TupleEntity implements WritableComparable<TupleEntity> {

	private IntWritable flag;
	private Text text1;
	private Text text2;
	private IntWritable int1;
	private IntWritable int2;
	private DoubleWritable double1;
	private DoubleWritable double2;

	 
	public IntWritable getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag.set(flag);
	}

	public Text getText1() {
		return text1;
	}

	public void setText1(String string) {
		this.text1.set(string);
	}

	public Text getText2() {
		return text2;
	}

	public void setText2(String string) {
		this.text2.set(string);
	}

	public IntWritable getInt1() {
		return int1;
	}

	public void setInt1(int int1) {
		this.int1.set(int1);
	}

	public IntWritable getInt2() {
		return int2;
	}

	public void setInt2(int int2) {
		this.int2.set(int2);
	}

	public DoubleWritable getDouble1() {
		return double1;
	}

	public void setDouble1(double double1) {
		this.double1.set(double1);
	}

	public DoubleWritable getDouble2() {
		return double2;
	}

	public void setDouble2(double double2) {
		this.double2.set(double2);
	}

	public TupleEntity() {
		flag=new IntWritable(0);
		text1=new Text("null");
		text2=new Text("null");
		int1=new IntWritable(0);
		int2=new IntWritable(0);
		double1=new DoubleWritable(0);
		double2=new DoubleWritable(0);
	}

	public static TupleEntity copy(TupleEntity e){
		TupleEntity ret=new TupleEntity();
		ret.setFlag(e.getFlag().get());
		ret.setText1(e.getText1().toString());
		ret.setText2(e.getText2().toString());
		ret.setInt1(e.getInt1().get());
		ret.setInt2(e.getInt2().get());
		ret.setDouble1(e.getDouble1().get());
		ret.setDouble2(e.getDouble2().get());
		return ret;
	}
	@Override
	public void readFields(DataInput dateInput) throws IOException {
		// TODO Auto-generated method stub
		this.flag.readFields(dateInput);
		this.text1.readFields(dateInput);
		this.text2.readFields(dateInput);
		this.int1.readFields(dateInput);
		this.int2.readFields(dateInput);
		this.double1.readFields(dateInput);
		this.double2.readFields(dateInput);
	}

	@Override
	public void write(DataOutput outPut) throws IOException {
		this.flag.write(outPut);
		this.text1.write(outPut);
		this.text2.write(outPut);
		this.int1.write(outPut);
		this.int2.write(outPut);
		this.double1.write(outPut);
		this.double2.write(outPut);
	}

	@Override
	public int compareTo(TupleEntity o) {
		// TODO Auto-generated method stub
		if(!this.getText1().toString().equals(o.getText1().toString()) ) return this.getText1().toString().compareTo(o.getText1().toString());
		if(!this.getText2().toString().equals(o.getText2().toString()) ) return this.getText2().toString().compareTo(o.getText2().toString());
		if(this.getInt1().get()!=o.getInt1().get()) return this.getInt1().get()-o.getInt1().get();
		if(this.getInt2().get()!=o.getInt2().get()) return this.getInt2().get()-o.getInt2().get();
		return 0;
	}
}
